package cytest.embedded;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Hello world!
 *
 */

@SpringBootApplication
@RestController
@RequestMapping("/embedded")
public class App implements CommandLineRunner {
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);  
	}

	@Autowired
	H2CommandProcessor processor;

	public void run(String... args) throws Exception {
		// TODO Auto-generated method stub
		processor.initPassword();
		processor.create();
	}

	@RequestMapping(value = "/insert/{id}", method = RequestMethod.GET)
	public void insert(@PathVariable String id) {
		processor.insert(new User(id, "xuefei", 27));
	}

	@RequestMapping("/query")
	public User query(@RequestParam String id) {
		return processor.query(id);
	}
}
